package daily.may0508;

import java.util.ArrayList;
import java.util.Iterator;

public class ForEachMethodTest {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        //添加元素
        for (int i = 0; i < 5; i++) {
            list.add(i);
        }
        //用Iterator迭代器遍历
        Iterator<Integer> ite = list.iterator();
        while(ite.hasNext()){
            System.out.print(ite.next());
        }
        //用forEach方法结合lambda表达式遍历集合
        list.forEach(j -> System.out.print(j));
        //用foreach循环遍历
        for(int k:list){
            System.out.print(k);
        }
    }
}
